package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.service.LineServiceLPN;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class LineActionLPN extends ActionSupport implements SessionAware,ServletRequestAware,ServletResponseAware{
	private HttpServletRequest req;
	private HttpServletResponse resp;
	private Map<String, Object> session;
	private int page;
	private int rows;
	private String lineEndPoint;
	private String loStart;
	private String lineStartPoint;
	private String loStop; 
	private String loTransferStation1; 
	private String loTransferStation2;
	private int orId;
	
	public String getLoStop() {
		return loStop;
	}

	public void setLoStop(String loStop) {
		this.loStop = loStop;
	}

	public String getLoTransferStation1() {
		return loTransferStation1;
	}

	public void setLoTransferStation1(String loTransferStation1) {
		this.loTransferStation1 = loTransferStation1;
	}

	public String getLoTransferStation2() {
		return loTransferStation2;
	}

	public void setLoTransferStation2(String loTransferStation2) {
		this.loTransferStation2 = loTransferStation2;
	}

	public int getOrId() {
		return orId;
	}

	public void setOrId(int orId) {
		this.orId = orId;
	}

	public String getLineStartPoint() {
		return lineStartPoint;
	}

	public void setLineStartPoint(String lineStartPoint) {
		this.lineStartPoint = lineStartPoint;
	}

	public String getLoStart() {
		return loStart;
	}

	public void setLoStart(String loStart) {
		this.loStart = loStart;
	}

	public HttpServletRequest getReq() {
		return req;
	}

	public void setReq(HttpServletRequest req) {
		this.req = req;
	}

	public HttpServletResponse getResp() {
		return resp;
	}

	public void setResp(HttpServletResponse resp) {
		this.resp = resp;
	}

	public String getLineEndPoint() {
		return lineEndPoint;
	}

	public void setLineEndPoint(String lineEndPoint) {
		this.lineEndPoint = lineEndPoint;
	}

	public LineServiceLPN getLs() {
		return ls;
	}

	public void setLs(LineServiceLPN ls) {
		this.ls = ls;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

			//属性注入
			@Resource
			private  LineServiceLPN ls;
			
	/**
	 * 得到线路信息
	 * @throws IOException 
	 */
	public void getline() throws IOException{
	
		resp.setCharacterEncoding("utf8");
		JSONObject j= ls.getline(page, rows);
		PrintWriter pw = resp.getWriter();
		pw.write(j.toString());
		pw.flush();
		pw.close();
	}
	
	
	/**
	 * 得到中转站1
	 * @throws IOException 
	 */
	public void findTranSta1() throws IOException{
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		lineEndPoint=URLDecoder.decode(lineEndPoint,"UTF-8");
		
		JSONArray j= ls.findTranSta1(lineEndPoint);
		PrintWriter pw = resp.getWriter();
		pw.write(j.toString());
		pw.flush();
		pw.close();
		
	}
	
	/**
	 * 得到中转站2
	 * @throws IOException 
	 */
	public void findTranSta2() throws IOException {

		resp.setCharacterEncoding("utf8");
		lineStartPoint=URLDecoder.decode(lineStartPoint,"UTF-8");
		JSONArray j= ls.findTranSta2(lineStartPoint);
		PrintWriter pw = resp.getWriter();
		pw.write(j.toString());
		pw.flush();
		pw.close();
		
	}
	
	
	/**
	 * 增加订单线路
	 * @throws IOException 
	 */
	public void insertOrderLine() throws IOException{
		boolean flag = ls.insertOrderLine(loStart, loStop, loTransferStation1, loTransferStation2, orId);
		PrintWriter pw = resp.getWriter();
		if (flag) {
			pw.write("1");
		} else {
			pw.write("0");
		}
		
		pw.flush();
		pw.close();
	}
	
	
	
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.resp=arg0;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.req=arg0;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		this.session=arg0;
	}

}
